package org.crazyit.activiti_d2._8_SingleResult;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.Group;
import org.crazyit.activiti_d2._2_ListData.ListData;

import java.util.UUID;

public class SingleResult {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到身份服务组件实例
        IdentityService identityService = engine.getIdentityService();

        //3. 写入一条新数据
        ListData.createGroup(identityService, UUID.randomUUID().toString(),"GroupA","typeF");

        //4. 查询名称为Group D 的记录
        Group groupD = identityService.createGroupQuery().groupName("GroupD").singleResult();
        System.out.println("查询到一条GroupB 数据: " + groupD.getId() + "---" + groupD.getName());

        //5. 查询名称为Group F 的记录
        Group groupF = identityService.createGroupQuery().groupName("GroupF").singleResult();
        System.out.println("没有groupF 的数据: " + groupF);

        //6. 查询名称为Group A 的记录, 这里将抛出异常
        Group groupA = identityService.createGroupQuery().groupName("GroupA").singleResult();

    }

}
